package com.yuntsg.nnsfcp.service.back;

import com.yuntsg.nnsfcp.front.entity.Backconfig;
import com.yuntsg.nnsfcp.front.mapper.BackconfigMapper;
import com.yuntsg.nnsfcp.service.front.ut.DateUtil;
import com.yuntsg.nnsfcp.util.MD5;
import com.yuntsg.nnsfcp.util.httpclient.HttpClient;
import com.yuntsg.nnsfcp.util.httpclient.HttpClientConfig;
import com.yuntsg.nnsfcp.util.httpclient.HttpClientUtil;
import org.apache.http.impl.client.BasicCookieStore;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class UtilService {

    @Resource
    BackconfigMapper backconfigMapper;

    /**
     * 根据模板进行发送短信
     *
     * @param phone
     * @param template
     * @return
     */
    public void generatorJNDXSmsParam(String phone, int template) {
        Backconfig backconfigs = backconfigMapper.selectById(1);
        if (backconfigs.getFlag() == 1) {
            String start = "您提交的订单已经开始处理,请留意个人中心的订单进度";
            String midel = "您提交的订单已经分配馆员,请留意个人中心的订单进度";
            String end = "您提交的订单处理完毕,形成初始报告,请留意图书馆电话";
            String url = "https://libapi.jnu.edu.cn/libapi/auth/sms/sendMessage";
            String appid = "chaxin";
            String secret = "ff80808172499f9a01729d202a1c0002";
            String currentYmdStr = DateUtil.longToDate_ymdhms();
            String md5Code = MD5.string2MD5(secret + currentYmdStr + appid);

            Map paramMap = new HashMap();
            String hashcode = "";
            if (template == 1) {
                hashcode = start;
            } else if (template == 2) {
                hashcode = midel;
            } else {
                hashcode = end;
            }
            paramMap.put("mobile", phone);
            paramMap.put("content", hashcode);
            paramMap.put("appid", appid);
            paramMap.put("seccode", md5Code);
            try {
                HttpClientConfig clientConfig = HttpClientUtil.getSearConfig(url, "", "", false);
                String s1 = HttpClient.postHtml(new BasicCookieStore(), paramMap, clientConfig);
                System.out.println(s1);
            } catch (Exception e) {
            }
        }


    }
}
